import config
from PySide2.QtUiTools import QUiLoader
import VoltageTest
import DiffVoltageTest
import CurrentTest

# 功能：初始化设备ID、选定测试内容
class LinkInitWindows:
    def __init__(self):
        self.init_device = config.get_init_device_value() # 获取初始化测试类型
        self.link_init = QUiLoader().load("./UI/SetParameterSelect.ui")  #加载图形界面
        self.link_init.TestVoltageButt.clicked.connect(self.test_voltage) #点击【测试电压】
        self.link_init.TestCurrentButt.clicked.connect(self.test_current) #点击【测试电流】
        self.link_init.TestVoltageDiffButt.clicked.connect(self.test_voltage_diff)#点击【测试电压差】
        self.window = None
        self.link_init.setWindowTitle("【古鑫】安捷伦34465 测试软件 V1.0")

    # 读取测试型号、设备ID、测试类型（电压测试）
    def test_voltage(self):
        self.init_device['TestModel'] = self.link_init.TestModeText.text()
        self.init_device['BatchNo'] = self.link_init.BatchNo.text()
        self.init_device['ScanDeviceID'] = self.link_init.DeviceIDText.text()
        self.init_device['TestType'] = 'TypeVoltage'
        self.init_device['small_statistics'] = self.link_init.small_statistics.text()
        self.init_device['small_statistics_box'] = self.link_init.small_statistics_box.checkState()
        config.change_init_device_value(self.init_device)

        self.window = VoltageTest.MainWindowVoltage()
        self.window.ui.show()
        self.link_init.close()

    # 读取测试型号、设备ID、测试类型（电压差测试）
    def test_voltage_diff(self):
        self.init_device['TestModel'] = self.link_init.TestModeText.text()
        self.init_device['BatchNo'] = self.link_init.BatchNo.text()
        self.init_device['ScanDeviceID'] = self.link_init.DeviceIDText.text()
        self.init_device['TestType'] = 'TestVoltageDiff'
        self.init_device['small_statistics'] = self.link_init.small_statistics.text()
        self.init_device['small_statistics_box'] = self.link_init.small_statistics_box.checkState()

        self.window = DiffVoltageTest.MainWindowDiff()
        self.window.ui.show()
        self.link_init.close()

    # 读取测试型号、设备ID、测试类型（电流测试）
    def test_current(self):
        self.init_device['TestModel'] = self.link_init.TestModeText.text()
        self.init_device['BatchNo'] = self.link_init.BatchNo.text()
        self.init_device['ScanDeviceID'] = self.link_init.DeviceIDText.text()
        self.init_device['TestType'] = 'TypeCurrent'
        self.init_device['small_statistics'] = self.link_init.small_statistics.text()
        self.init_device['small_statistics_box'] = self.link_init.small_statistics_box.checkState()

        self.window = CurrentTest.MainWindowCurrent()
        self.window.ui.show()
        self.link_init.close()
